<meta charset="utf-8" />
<div class="breadcrumbs" id="breadcrumbs">
	<ul class="breadcrumb">
		<li><i class="ace-icon fa fa-home home-icon"></i> <a href="index">生产计划管理</a>
		</li>
		<li><span>销售订单信息管理</span>
		</li>
	</ul>
	<!-- /.breadcrumb -->
</div>

<div class="page-content">
	<div class="row">
		<div class="col-xs-12">					<!-- 66666 -->
			<div class="clearfix"></div>
				
				
				<div class="table-header">销售订单信息</div>
				
				<div class="tab-content">
					<!-- 不同的内容 -->
					<div class="tab-pane active" id="tab1">			
						<div id="dynamic-table_wrapper" class="dataTables_wrapper form-inline no-footer">
							<div class="row">
								<div class="col-xs-12">
									<form id="pc_form" class="form-search" action="" method="post">
										<div id="dynamic-table_filter" class="pull-left">
											<label><input id="table1_search1" name="searchValue" type="search" placeholder="请输入销售订单号..." aria-controls="dynamic-table"> </label> <label><input id="table1_search2" name="searchValue" type="search" placeholder="请输入客户简称..." aria-controls="dynamic-table"> </label> <label><input id="table1_search3" name="searchValue" type="search" placeholder="请输入存货编码..." aria-controls="dynamic-table"> </label>
											<lable  class=" btn btn-info btn-sm">查询</lable>
										</div>
									</form>
									
									<div class="pull-right col-xs-0">
                                        <form id="sub" action="date/excleIn" method="post" enctype="multipart/form-data"> 
										<input type="button" name="filename" id="fileselect"  onMouseOver="mouseOver();" onMouseOut="mouseOut();"  class="btn btn-mini btn-primary"  value="导入订单信息"/>
                                        <a href="javascript:addForm()" class="btn btn-mini btn-primary">添加新订单</a>  <a href="#" class="btn btn-mini btn-primary">打印</a>  <a id="pc1" href="" class="btn btn-mini btn-primary">生成生产订单</a>
                                        <a  href="xsddxxgl/zdsc" class="btn btn-mini btn-primary">自动生成生产订单</a>  
									    </form> 
									</div>
								</div>
							</div>
						</div>

						<table class="table table-striped table-bordered table-hover dataTable no-footer DTTT_selectable" role="grid">
							<thead>
								<tr role="row">
									<th class="center"><label> <input type="checkbox" class="ace" /> <span class="lbl"></span> </label></th>
									<th>销售订单号</th>
									<th>客户简称</th>
									<th>存货编码</th>
									<th>存货名称</th>
									<th>规格型号</th>
									<th>单位</th>
									<th>订单数量</th>
									<th>发货日期</th>
									<th>备注</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody id="table_1"> </tbody>
						</table>
						<div class="breadcrumbs" id="breadcrumbs">    		 <!-- 分页 -->
							<div class="text-right">
								<ul id="pagefoot1" class="pagination">
									
								</ul>
							</div>
						</div>
					</div>

				</div>


		</div>
	</div>
</div>



<!-- 新增销售订单 -->
	<div class="hide" id="add">			
		<form id="pform" action="xsddxxgl/add" method="post">
			<!-- <input type="hidden" name="id"> -->
			<!-- 在div中隐藏 -->
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">销售订单号：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" placeholder="请输入销售订单号"  name="scjhgl_scdd.xsddh" value=""/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">客户简称：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" placeholder="请输入客户简称" name="scjhgl_scdd.khjc" value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">存货编码：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" placeholder="请输入存货编码" name="scjhgl_scdd.chbm" value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">存货名称：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" placeholder="请输入存货名称" name="scjhgl_scdd.chmc" value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">规格型号：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" placeholder="请输入规格型号" name="scjhgl_scdd.ggxh" value="" />
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">单位：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" placeholder="请输入单位" name="scjhgl_scdd.dw" value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">订单数量：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" placeholder="请输入订单数量" name="scjhgl_scdd.ddsl" value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">发货日期：</label>
				<div class="col-sm-9">
					<input type="date" class="form-control" placeholder="请输入发货日期" name="scjhgl_scdd.fhrq" value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">备注：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" placeholder="请输入备注" name="scjhgl_scdd.bz" value="" />
				</div>
			</div>
		</form>
	</div>


 

<!--修改销售订单信息  -->
	<div class="hide" id="update1">	
	<div class="col-xs-2"></div>
					<div class="col-xs-8">
		<form id="updateFormA" action="xsddxxgl/u" method="post">
		<input type="text" name="scjhgl_scdd.id" type="hidden" id="id" class="hide"><!--js中通过id来显示表单数据 ,在js中隐藏  -->
					
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">销售订单号：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" name="scjhgl_scdd.xsddh" id="xsddh" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">客户简称：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" name="scjhgl_scdd.khjc" id="khjc" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">存货编码：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" name="scjhgl_scdd.chbm" id="chbm" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">存货名称：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" name="scjhgl_scdd.chmc" id="chmc" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">规格型号：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" name="scjhgl_scdd.ggxh" id="ggxh" />
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">单位：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" name="scjhgl_scdd.dw" id="dw" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">订单数量：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" name="scjhgl_scdd.ddsl" id="ddsl" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">发货日期：</label>
				<div class="col-sm-9">
					<input type="date" class="form-control" name="scjhgl_scdd.fhrq" id="fhrq" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">备注：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" name="scjhgl_scdd.bz" id="bz" />
				</div>
			</div>
		</form>
	</div>
</div>





	<script type="text/javascript">	
	   // 导入订单信息
		function mouseOver() {
			$("#fileselect").attr('value', '');
			$("#fileselect").attr('type', 'file');
			$("#fileselect").change(function() {
				
				$("#sub").submit();
			});
		}
		
		function mouseOut() {
			$("#fileselect").attr('type', 'button');
			$("#fileselect").attr('value', '导入订单信息');
		}
/*按条件查询  */	   
$("#table1_search1").blur( function () {   	
		  var a =""; 
		  a=document.getElementById("table1_search1").value;     //获取search1输入的值   //js条件模糊查询 失去焦点后查询
		  search1(1,a);						//调用find function
		} );  
		$("#table1_search2").blur( function () {   
		  var a =""; 
		  a=document.getElementById("table1_search2").value;     //获取search2输入的值
		  search1(1,a);						//调用find function
		} ); 
		$("#table1_search3").blur( function () {   
		  var a =""; 
		  a=document.getElementById("table1_search3").value;     //获取search3输入的值
		  search1(1,a);						//调用find function
		} ); 
		function search1(curr,require){
			$.post("xsddxxgl/search1",{"pageNumber": curr,"require":require},function(data) {
				trList1(data.list); //调用trList()方法，填充表格数据
				PageFoot1(data); //调用下面的writePageFoot方法，循环输出页码连接  
			});
		}	
	
	
		function WPC(v) {     			 //销售订单未排产
			var dataStr = "";
			dataStr += '<tr>';				
			dataStr += '<td><input class="ace" name="checkboxs" id="checkboxs" type="checkbox" value="'+v.id+'"> <span class="lbl"></span></td>';  	//<form name="pc1" action="scjhgl/PC1" method="post"></form>
			dataStr += '<td>' + v.xsddh + '</td>';
			dataStr += '<td>' + v.khjc + '</td>';
			dataStr += '<td>' + v.chbm + '</td>';
			dataStr += '<td>' + v.chmc + '</td>';
			dataStr += '<td>' + v.ggxh + '</td>';	
			dataStr += '<td>' + v.dw + '</td>';
			dataStr += '<td>' + v.ddsl + '</td>';	
			dataStr += '<td class=" fhrq'+v.id+'">' + v.fhrq + '</td>';	
			dataStr += '<td>' + v.bz + '</td>';  
			dataStr += '<td><div class="hidden-sm hidden-xs action-buttons"><a class="green" href="javascript:updateForm1('+v.id+',\''+v.xsddh+'\',\''+v.khjc+'\',\''+v.chbm+'\',\''+v.chmc+'\',\''+v.ggxh+'\',\''+v.fhrq+'\',\''+v.dw+'\',\''+v.ddsl+'\',\''+v.bz+'\')"> <i class="ace-icon fa fa-pencil bigger-130"></i> </a> <a href="javascript:Delete('+v.id+')" class="red"> <i class="ace-icon fa fa-trash-o bigger-130"></i> </a></div><div class="hidden-md hidden-lg"><div class="inline pos-rel"><button data-position="auto" data-toggle="dropdown" class="btn btn-minier btn-yellow dropdown-toggle"><i class="ace-icon fa fa-caret-down icon-only bigger-120"></i></button><ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close"><li><a href="scjhgl/toUpdateUser?id='+v.id+'" class="tooltip-success" data-rel="tooltip" title=""> <span class="green"> <i class="ace-icon fa fa-pencil-square-o bigger-120"></i> </span> </a></li><li><a title="" data-rel="tooltip" class="tooltip-error" href="scjhgl/d/'+v.id+'" data-original-title="Delete"> <span class="red"> <i class="ace-icon fa fa-trash-o bigger-120"></i> </span> </a></li></ul></div></div></td>';
			dataStr += '</tr>';                                                                                            
			return dataStr;
		}
		
	    //获取分页数据列表并显示
		function showPage1(curr) {  
			$.get("xsddxxgl/Tbody_list1", {"pageNumber": curr}, function(data) {
				trList1(data.list); 		//调用trList()方法，填充表格数据
				PageFoot1(data); 		   //调用的PageFoot方法，循环输出页码连接  
			});
		}
		showPage1(1);   		//~暂不理解 ,应该是刚进入页面为第一页，列出第一页数据和页脚
		
		function trList1(data) {
			var dataStr = "";
			$.each(data, function(i, v) {
				dataStr += WPC(v);
			});
			// 把拼接好的表格内容填充到指定位置
			$("#table_1").html(dataStr);
			
			 var now = new Date();    //获取当前时间----------------
       
             var year = now.getFullYear();       //年
             var month = now.getMonth() + 1;     //月
             var day = now.getDate();            //日
             var clock = year + "-";
             if(month < 10)
               clock += "0";
               clock += month + "-";
             if(day < 10)
               clock += "0";
               clock += day + " ";
               //alert(clock);  //当天时间         获取时间结束-------------------------
        	$.each(data, function(i, v) {
				 var fhrq = $("#table_1 .fhrq"+v.id).text();
				 //alert(fhrq); //发货日期
				 //difference = fhrq.getTime() - clock.getTime();
				 // alert(difference);
                 var OneMonth = fhrq.substring(5,fhrq.lastIndexOf ('-'));    //时间相减-------------
                 var OneDay = fhrq.substring(fhrq.length,fhrq.lastIndexOf ('-')+1);  
                 var OneYear = fhrq.substring(0,fhrq.indexOf ('-'));  
  
                var TwoMonth = clock.substring(5,clock.lastIndexOf ('-'));  
                var TwoDay = clock.substring(clock.length,clock.lastIndexOf ('-')+1);  
                var TwoYear = clock.substring(0,clock.indexOf ('-'));  
  
                var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)- Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000);    //时间相减-------------
                 // alert(cha);
			 	 				
			if(cha<='3'){
			$("#table_1 .fhrq"+v.id).parent().css("background-color","red");}
			 else if ('3'<cha && cha<'8'){
			$("#table_1 .fhrq"+v.id).parent().css("background-color","yellow"); }
			
			});
			
																						
}
		function PageFoot1(data){
			var n="";
			var backword="上一页";
			var forword="下一页";
			var x=data.PageNumber; //当前页
			var back;		//前一页
			var next;       //后一页
			if(x=1){            	//对上一页的判断		
				back =1;
			}else{
				back=x-1;   		
			}
			if(x<data.totalPage){   //对下一页判断
				next=x+1;
			}else{
				next=data.totalPage;		
			}
			
			n+="<li onclick=\"showPage1("+back+")\"><a>"+backword+"</a></li>&nbsp;&nbsp;";
			for(var a=1;a<=data.totalPage;a++){
				if(a==data.PageNumber){
					n +="<li class=\"active\" onclick=\"showPage1("+a+")\"><a>"+a+"</a></li>&nbsp;&nbsp;";
				}else{
					n +="<li onclick=\"showPage1("+a+")\"><a>"+a+"</a></li>&nbsp;&nbsp;";
				};
			}
			n+="<li onclick=\"showPage1("+next+")\"><a>"+forword+"</a></li>&nbsp;&nbsp;";
			
			$("#pagefoot1").html(n);       //把循环好的页码给替换掉
		};
</script>		


	<script type="text/javascript">
	/*将销售订单进行转换  */
	$("#pc1").click(function(event){
		var ls = $("input[type=checkbox]:checked").size();   		//选中的个数
            if (ls != "") {
            	
                layer.confirm('确定排产？', {
		  			btn: ['确认','取消'] //按钮
					}, function(){
					var idlist='';
					$("input[type='checkbox'][name='checkboxs']").filter(':checked').each(function() {
                idlist = idlist + $(this).val() + ",";
                });
                if(idlist.length>0){
                idlist = idlist.substring(0,idlist.length-1);
                $.post("xsddxxgl/PC1",{"idlist":idlist},function(data){
                	if(data=="success"){
                		location.reload();
                		idlist='';
                	}
                });
                }
				layer.colse();
		}, function(){
			layer.msg("已取消"); 
		});
            } else {
                layer.alert("请选择要排产的数据！");
            }
	return false;
	});		
		
		
/*已排产的进行排产  */		
/* $("#pc2").click(function(event){
		var ls = $("input[type=checkbox]:checked").size();   		//选中的个数
            if (ls != "") {
            	
                layer.confirm('确定排产？', {
		  			btn: ['确认','取消'] //按钮
					}, function(){
					var idlist='';
					$("input[type='checkbox'][name='checkboxs2']").filter(':checked').each(function() {
                idlist = idlist + $(this).val() + ",";
                });
                if(idlist.length>0){
                idlist = idlist.substring(0,idlist.length-1);
                $.post("scjhgl/PC2",{"idlist":idlist},function(data){
                	if(data=="success"){
                		location.reload();
                		idlist='';
                	}
                });
                }
				layer.colse();
		}, function(){
			layer.msg("已取消"); 
		});
            } else {
                layer.alert("请选择要排产的数据！");
            }
	return false;
	}); */			
		
		
        
        function BD(){
        	 var ls = $("input[type=checkbox]:checked").size();   		//选中的个数
            if (ls != "") {
                layer.confirm("确定闭单？", function () {
							var ids = new Array([checkboxs2.length]);  
							var j = 0;
							for (var i=0;i<checkboxs2.length;i++ ){   //checkboxs为id名
								if(checkboxs2[i].checked){		 //判断复选框是否选中
									ids[j]=checkboxs2[i].value; 	 //值的拼凑 .. 具体处理看需要
									j++;
								}
							}
						//alert(ids);//输出你选中的那些复选框的值
						 for(var s=0;s<ids.length;s++ ){
                         $.updateByUrl("scjhgl/BD/"+ids[s]);  
                         }
                });
            } else {
                layer.alert("请选择要闭单的数据！");
            }
        }
        	 
/*删除销售订单  */	 
	        function Delete(id) {
        	 		if(id!=null){
	                layer.confirm("确定删除？", function () {
	                $.post("xsddxxgl/delete?id="+id,function(data){
	                	if(data=="success"){
	                		location.reload();
	                	}
	                });
	                     //$.updateByUrl("scjhgl/d?id="+id);
	                });
	               }else{
	               	layer.alert("请选择要删除的数据！");
	              }
	        }
	        
	        
	        
	       	
		$('table th input:checkbox').on('click' , function(){   		 /*复选框js_全选  */
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
						
		});
		
		
		
		
/*增加销售订单  */				
		function addForm() {
			document.getElementById("pform").reset();
			$('#add').removeClass("hide");
			userModel = layer.open({
				type : 1,
				shade : [ 0.5 ],
				title : '增加销售订单',  //不显示标题
				area : [ '40%', '430px' ], //显示空间
				content : $('#add'), //捕获的元素
				btn : [ '确定', '取消' ],
				yes : function(index, layero) { //或者使用btn1
					$.post("add", $("#pform").serialize(), function(data) {

						layer.close(index);
						$('#add').addClass("hide");
						document.getElementById("pform").submit();
					});
				},
				cancel : function(index) {
					layer.close(index);
					$('#add').addClass("hide"); //取消继续隐藏
				},
			});
		};
	</script>

<script>
/*修改销售订单 */
function updateForm1(id,xsddh,khjc,chbm,chmc,ggxh,fhrq,dw,ddsl,bz) {
						document.getElementById("updateFormA").reset();
						                        $("#id").val(id);
												$("#xsddh").val(xsddh);
												$("#khjc").val(khjc);
												$("#chbm").val(chbm);
												$("#chmc").val(chmc);
												$("#ggxh").val(ggxh);
												$("#fhrq").val(fhrq);
												$("#dw").val(dw);
												$("#ddsl").val(ddsl);
												$("#bz").val(bz);
						$('#update1').removeClass("hide");
						userModel = layer.open({
							type : 1,
							shade : [ 0.5 ],
							title : '修改销售订单信息', //不显示标题
							area : [ '60%', '420px' ], //显示空间
							content : $('#update1'), //捕获的元素
							btn : [ '确定', '取消' ],
							yes : function(index, layero) { //或者使用btn1
								$.post("update1", $("#updateFormA").serialize(),
										function(data) {

											layer.close(index);
											$('#update1').addClass("hide");
											document.getElementById("updateFormA")
													.submit();
										});
							},
							cancel : function(index) {
								layer.close(index);
								$('#update1').addClass("hide"); //取消继续隐藏
							},
						});
					};
</script>
<script>
/*修改销售订单2 */	
/* function updateForm2(id,ddh,khjc,chbm,chmc,ggxh,fhrq,dw,sl,ypcsl,dpcsl,bz) {
						document.getElementById("updateFormB").reset();
						                        $("#id2").val(id);
												$("#ddh2").val(ddh);
												$("#khjc2").val(khjc);
												$("#chbm2").val(chbm);
												$("#chmc2").val(chmc);
												$("#ggxh2").val(ggxh);
												$("#fhrq2").val(fhrq);
												$("#dw2").val(dw);
												$("#sl2").val(sl);
												$("#ypcsl2").val(ypcsl);
												$("#dpcsl2").val(dpcsl);
												$("#bz2").val(bz);
						$('#update2').removeClass("hide");
						userModel = layer.open({
							type : 1,
							shade : [ 0.5 ],
							title : '修改销售订单信息', //不显示标题
							area : [ '60%', '500px' ], //显示空间
							content : $('#update2'), //捕获的元素
							btn : [ '确定', '取消' ],
							yes : function(index, layero) { //或者使用btn1
								$.post("update2", $("#updateFormB").serialize(),
										function(data) {

											layer.close(index);
											$('#update2').addClass("hide");
											document.getElementById("updateFormB")
													.submit();
										});
							},
							cancel : function(index) {
								layer.close(index);
								$('#update2').addClass("hide"); //取消继续隐藏
							},
						});
					}; */
	</script>

	
	<script type="text/javascript">
		jQuery(function($) {
			$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
				_title : function(title) {
					var $title = this.options.title || '&nbsp;';
					if (("title_html" in this.options)
							&& this.options.title_html == true)
						title.html($title);
					else
						title.text($title);
				}
			}));
			
			
			
			
			//initiate dataTables plugin						初始化表格插件
			/* var oTable1 = $('#dynamic-table')
			//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
			.dataTable({
				bAutoWidth : false,
				"aoColumns" : [ null, null, null, null, null, null, {
					"bSortable" : false
				} ],
				"aaSorting" : [],

			}); */
			//oTable1.fnAdjustColumnSizing();




			//TableTools settings
			TableTools.classes.container = "btn-group btn-overlap";
			TableTools.classes.print = {
				"body" : "DTTT_Print",
				"info" : "tableTools-alert gritter-item-wrapper gritter-info gritter-center white",
				"message" : "tableTools-print-navbar"
			};

			//initiate TableTools extension
			var tableTools_obj = new $.fn.dataTable.TableTools(
					oTable1,
					{
						"sSwfPath" : "plugins/ace/assets/js/dataTables/extensions/TableTools/swf/copy_csv_xls_pdf.swf", //in Ace demo plugins/ace/assets will be replaced by correct assets path

						"sRowSelector" : "td:not(:last-child)",
						"sRowSelect" : "multi",
						"fnRowSelected" : function(row) {
							//check checkbox when row is selected
							try {
								$(row).find('input[type=checkbox]').get(0).checked = true
							} catch (e) {
							}
						},
						"fnRowDeselected" : function(row) {
							//uncheck checkbox
							try {
								$(row).find('input[type=checkbox]').get(0).checked = false
							} catch (e) {
							}
						},

						"sSelectedClass" : "success",
						"aButtons" : [
								{
									"sExtends" : "copy",
									"sToolTip" : "复制到剪贴板",
									"sButtonClass" : "btn btn-white btn-primary btn-bold",
									"sButtonText" : "<i class='fa fa-copy bigger-110 pink'></i>",
									"fnComplete" : function() {
										this
												.fnInfo(
														'<h3 class="no-margin-top smaller">表格已复制</h3>\
							<p>已复制 '
																+ (oTable1
																		.fnSettings()
																		.fnRecordsTotal())
																+ ' 行数据到剪贴板.</p>',
														1500);
									}
								},

								{
									"sExtends" : "csv",
									"sToolTip" : "导出成 CSV",
									"sButtonClass" : "btn btn-white btn-primary  btn-bold",
									"sButtonText" : "<i class='fa fa-file-excel-o bigger-110 green'></i>"
								},

								{
									"sExtends" : "pdf",
									"sToolTip" : "导出成 PDF",
									"sButtonClass" : "btn btn-white btn-primary  btn-bold",
									"sButtonText" : "<i class='fa fa-file-pdf-o bigger-110 red'></i>"
								},

								{
									"sExtends" : "print",
									"sToolTip" : "打印页面",
									"sButtonClass" : "btn btn-white btn-primary  btn-bold",
									"sButtonText" : "<i class='fa fa-print bigger-110 grey'></i>",

									"sMessage" : "<div class='navbar navbar-default'><div class='navbar-header pull-left'><a class='navbar-brand' href='#'><small>可选导航栏 &amp; 文本</small></a></div></div>",

									"sInfo" : "<h3 class='no-margin-top'>打印页面</h3>\
							  <p>请用您的浏览器打印功能打印这个表格 \
							  <br />请打印完成关闭此页面</p>",
								} ]
					});

			//we put a container before our table and append TableTools element to it
			$(tableTools_obj.fnContainer())
					.appendTo($('.tableTools-container'));

			//also add tooltips to table tools buttons
			//addding tooltips directly to "A" buttons results in buttons disappearing (weired! don't know why!)
			//so we add tooltips to the "DIV" child after it becomes inserted
			//flash objects inside table tools buttons are inserted with some delay (100ms) (for some reason)
			setTimeout(function() {
				$(tableTools_obj.fnContainer()).find('a.DTTT_button').each(
						function() {
							var div = $(this).find('> div');
							if (div.length > 0)
								div.tooltip({
									container : 'body'
								});
							else
								$(this).tooltip({
									container : 'body'
								});
						});
			}, 200);

			//ColVis extension
			var colvis = new $.fn.dataTable.ColVis(oTable1, {
				"buttonText" : "<i class='fa fa-search'></i>",
				"aiExclude" : [ 0, 6 ],
				"bShowAll" : true,
				//"bRestore": true,
				"sAlign" : "right",
				"fnLabel" : function(i, title, th) {
					return $(th).text();//remove icons, etc
				}

			});

			//style it
			$(colvis.button()).addClass('btn-group').find('button').addClass(
					'btn btn-white btn-info btn-bold')

			//and append it to our table tools btn-group, also add tooltip
			$(colvis.button()).prependTo('.tableTools-container .btn-group')
					.attr('title', '显示/隐藏 数据列').tooltip({
						container : 'body'
					});

			//and make the list, buttons and checkboxed Ace-like
			$(colvis.dom.collection)
					.addClass(
							'dropdown-menu dropdown-light dropdown-caret dropdown-caret-right')
					.find('li').wrapInner('<a href="javascript:void(0)" />') //'A' tag is required for better styling
					.find('input[type=checkbox]').addClass('ace').next()
					.addClass('lbl padding-8');

			//table checkboxes
			$('th input[type=checkbox], td input[type=checkbox]').prop(
					'checked', false);

			//select/deselect all rows according to table header checkbox
			$('#dynamic-table > thead > tr > th input[type=checkbox]').eq(0)
					.on(
							'click',
							function() {
								var th_checked = this.checked;//checkbox inside "TH" table header

								$(this).closest('table').find('tbody > tr')
										.each(function() {
											var row = this;
											if (th_checked)
												tableTools_obj.fnSelect(row);
											else
												tableTools_obj.fnDeselect(row);
										});
							});

			//select/deselect a row when the checkbox is checked/unchecked
			$('#dynamic-table').on(
					'click',
					'td input[type=checkbox]',
					function() {
						var row = $(this).closest('tr').get(0);
						if (!this.checked)
							tableTools_obj.fnSelect(row);
						else
							tableTools_obj.fnDeselect($(this).closest('tr')
									.get(0));
					});

			$(document).on('click', '#dynamic-table .dropdown-toggle',
					function(e) {
						e.stopImmediatePropagation();
						e.stopPropagation();
						e.preventDefault();
					});

			//And for the first simple table, which doesn't have TableTools or dataTables
			//select/deselect all rows according to table header checkbox
			var active_class = 'active';
			$('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on(
					'click',
					function() {
						var th_checked = this.checked;//checkbox inside "TH" table header

						$(this).closest('table').find('tbody > tr').each(
								function() {
									var row = this;
									if (th_checked)
										$(row).addClass(active_class).find(
												'input[type=checkbox]').eq(0)
												.prop('checked', true);
									else
										$(row).removeClass(active_class).find(
												'input[type=checkbox]').eq(0)
												.prop('checked', false);
								});
					});

			//select/deselect a row when the checkbox is checked/unchecked
			$('#simple-table').on('click', 'td input[type=checkbox]',
					function() {
						var $row = $(this).closest('tr');
						if (this.checked)
							$row.addClass(active_class);
						else
							$row.removeClass(active_class);
					});

			/********************************/
			//add tooltip for small view action buttons in dropdown menu
			$('[data-rel="tooltip"]').tooltip({
				placement : tooltip_placement
			});

			//tooltip placement on right or left
			function tooltip_placement(context, source) {
				var $source = $(source);
				var $parent = $source.closest('table');
				var off1 = $parent.offset();
				var w1 = $parent.width();

				var off2 = $source.offset();
				//var w2 = $source.width();

				if (parseInt(off2.left) < parseInt(off1.left)
						+ parseInt(w1 / 2))
					return 'right';
				return 'left';
			}

		});
	</script>